﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Display.aswingui.*;

    public class HUDXPromoComponent extends HUDComponent implements IPlayerStateObserver {

        private static var m_hidden:Boolean = false;

        private const FLAG_PREFIX:String = "xpromo_anim_";

        private var m_icon:DisplayObject = null;
        private var m_iconHolder:AssetPane;
        private var m_locked:Boolean = false;
        private var m_created:Boolean = false;
        private var m_xml:XML;

        public function HUDXPromoComponent(){
            Global.player.addObserver(this);
        }
        override public function initWithXML(_arg1:XML):void{
            this.m_xml = _arg1;
            this.reset();
        }
        override public function reset():void{
            var _local3:Boolean;
            if (m_hidden){
                return;
            };
            alpha = 0;
            this.m_locked = false;
            var _local1:int = this.m_xml.@playerRequiredLevel;
            if ((((_local1 > 0)) && ((Global.player.level < _local1)))){
                this.m_locked = true;
            };
            var _local2:String = this.m_xml.@experiment;
            if (_local2 != ""){
                _local3 = (Global.experimentManager.getVariant(_local2) > 0);
                if (!_local3){
                    this.m_locked = true;
                };
            };
            if (((!(this.m_locked)) && (!(this.m_created)))){
                this.create();
                this.m_created = true;
            };
        }
        override public function isVisible():Boolean{
            return (((this.m_created) && (!(this.m_locked))));
        }
        protected function hide():void{
            removeEventListener(MouseEvent.CLICK, this.onMouseClick, false);
            Z_TweenLite.to(this, 2, {
                alpha:0,
                onComplete:this.doHide
            });
            m_hidden = true;
            this.m_locked = true;
        }
        protected function doHide():void{
            if (m_jWindow){
                m_jWindow.visible = false;
                m_jWindow.buttonMode = false;
            };
            this.m_locked = true;
        }
        private function create():void{
            m_jWindow = new JWindow(this);
            m_jPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, true);
            _local1.align = TextFormatAlign.RIGHT;
            this.addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
            m_jPanel.append(ASwingHelper.verticalStrut(15));
            var _local2:String = this.m_xml.@icon;
            var _local3:String = Global.getAssetURL(_local2);
            LoadingManager.load(_local3, this.onIconLoaded);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local4.append(ASwingHelper.horizontalStrut(0));
            m_jWindow.setContentPane(m_jPanel);
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.cacheAsBitmap = true;
            m_jWindow.show();
            this.alpha = 0;
            this.visible = false;
            if (!this.m_locked){
                this.visible = true;
                this.alpha = 1;
                Z_TweenLite.to(this, 1, {alpha:2});
                this.addTooltip();
            };
        }
        private function get animSeenFlag():String{
            return ((this.FLAG_PREFIX + this.m_xml.@type));
        }
        private function onIconLoaded(_arg1:Event):void{
            var _local4:int;
            var _local5:int;
            var _local6:int;
            var _local7:int;
            var _local8:AutoAnimatedBitmap;
            var _local9:Boolean;
            var _local2:Loader = (_arg1.target.loader as Loader);
            this.m_icon = _local2.content;
            var _local3:Bitmap = (this.m_icon as Bitmap);
            if ((((this.m_xml.@animated == 1)) && (_local3))){
                _local4 = this.m_xml.@animFrames;
                _local5 = this.m_xml.@animWidth;
                _local6 = this.m_xml.@animHeight;
                _local7 = this.m_xml.@animFPS;
                _local8 = new AutoAnimatedBitmap(_local3.bitmapData, _local4, _local5, _local6, _local7);
                _local8.x = 0;
                _local8.y = 0;
                _local9 = true;
                if (this.m_xml.@animateOnce == 1){
                    _local9 = !(Global.player.getSeenFlag(this.animSeenFlag));
                    if (_local9){
                        Global.player.setSeenFlag(this.animSeenFlag);
                    };
                };
                if (_local9){
                    _local8.play();
                } else {
                    _local8.stop();
                };
                this.m_icon = _local8;
            };
            addChildAt(this.m_icon, 0);
            m_jPanel.setPreferredSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            m_jPanel.setMinimumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            m_jPanel.setMaximumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.useHandCursor = true;
            m_jWindow.buttonMode = true;
            alpha = 0;
            Z_TweenLite.to(this, 2, {alpha:1});
        }
        private function onMouseClick(_arg1:Event):void{
            var _local2:String;
            var _local3:String;
            if (!this.m_locked){
                _local2 = this.m_xml.@clickStat;
                if (_local2 != ""){
                    StatsManager.count("xpromo", _local2, "hud_icon_clicks");
                };
                _local3 = this.m_xml.@announcement;
                StartUpDialogManager.displayAnnouncement(_local3);
                this.hide();
            };
        }
        private function addTooltip():void{
            var toolTip:* = null;
            toolTip = this.m_xml.@toolTip;
            if (toolTip == ""){
                return;
            };
            m_toolTip = new ToolTip(function ():String{
                return (ZLoc.t("Dialogs", toolTip));
            });
            m_toolTip.attachToolTip(m_jPanel);
            m_toolTip.hideCursor = true;
        }
        public function levelChanged(_arg1:int):void{
        }
        public function xpChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }

    }
}//package Display.hud.components 
